﻿using Controller.Enum;
using DPS.Enum;
using DPS.Model;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ControllerManageServer.ActionModel.Aioi
{
    abstract class AioiActionModelAbstract : ActionModelAbstract
    {

        #region 滚动功能,MWU2414专用
        /// <summary>
        /// MWU2414专用
        /// </summary>
        public class Scroll
        {
            private Scroll() { }
            private string bin;
            /// <summary>
            /// 值转换--内部用
            /// </summary>
            internal string BinValue { get { return bin; } }
            /// <summary>
            /// 通用，没有滚动条功能
            /// </summary>
            public static Scroll OFF { get { return new Scroll { bin = "0011" }; } }

            /// <summary>
            /// MWU2414专用速度:有滚动条功能
            /// </summary>
            public static Scroll ON { get { return new Scroll { bin = "0001" }; } }
            /// <summary>
            /// MWU2414专用速度:有滚动条功能(一时停止）
            /// </summary>
            public static Scroll ON_STOP { get { return new Scroll { bin = "0010" }; } }
            /// <summary>
            /// MWU2414专用速度:不改变
            /// </summary>
            public static Scroll No_Change { get { return new Scroll { bin = "0010" }; } }


        }
        #endregion 滚动功能,MWU2414专用

        #region 动作BIN

        /*
        MWU2414
        0001：标准
        0010：快速
        0011：最快
        1111：不改变
        正常标签
        0001：灭 灯
        0010：亮 灯
        0011：闪 烁
        0100：高速闪烁
        0111：不变化
        */
        public class Bin
        {
            private Bin() { }
            private string bin;
            /// <summary>
            /// 值转换--内部用
            /// </summary>
            public string Value { get { return bin; } }

            /// <summary>
            /// MWU2414专用速度:标准
            /// </summary>
            public static Bin SPEEP { get { return new Bin { bin = "0001" }; } }
            /// <summary>
            /// MWU2414专用速度:快速
            /// </summary>
            public static Bin SPEEP_Fast { get { return new Bin { bin = "0010" }; } }
            /// <summary>
            /// MWU2414专用速度:最快
            /// </summary>
            public static Bin SPEEP_Best { get { return new Bin { bin = "0011" }; } }
            /// <summary>
            /// MWU2414专用速度:不改变
            /// </summary>
            public static Bin SPEEP_No_Change { get { return new Bin { bin = "1111" }; } }
            /// <summary>
            /// 灭
            /// </summary>
            public static Bin OFF { get { return new Bin { bin = "0001" }; } }
            /// <summary>
            /// 亮(MWU2414:高速)
            /// </summary>
            public static Bin ON { get { return new Bin { bin = "0010" }; } }
            /// <summary>
            /// 闪
            /// </summary>
            public static Bin Sparkle { get { return new Bin { bin = "0011" }; } }
            /// <summary>
            /// 快闪
            /// </summary>
            public static Bin FastSparkle { get { return new Bin { bin = "0100" }; } }
            /// <summary>
            /// 不变化
            /// </summary>
            public static Bin NoChange { get { return new Bin { bin = "0111" }; } }
        }

        #endregion

        #region 亮灯颜色

        /// <summary>
        /// 亮灯颜色
        /// </summary>
        public class Color
        {
            private Color(Bin led2, Bin led1, Bin led0)
            {
                Led2Bin = led2.Value; Led1Bin = led1.Value; Led0Bin = led0.Value;
            }
            private string Led2Bin;
            private string Led1Bin;
            private string Led0Bin;
            /// <summary>
            /// 组合BIN值
            /// </summary>
            public string Value { get { return Led2Bin + Led1Bin + Led0Bin; } }
            /// <summary>
            /// 不变化
            /// </summary>
            public static Color NoChange { get { return new Color(Bin.NoChange, Bin.NoChange, Bin.NoChange); } }
            /// <summary>
            /// 灭灯
            /// </summary>
            public static Color OFF { get { return new Color(Bin.OFF, Bin.OFF, Bin.OFF); } }

            /// <summary>
            /// 亮白
            /// </summary>
            public static Color White { get { return new Color(Bin.ON, Bin.ON, Bin.ON); } }
            /// <summary>
            /// 闪白
            /// </summary>
            public static Color White_S { get { return new Color(Bin.Sparkle, Bin.Sparkle, Bin.Sparkle); } }
            /// <summary>
            /// 快闪白
            /// </summary>
            public static Color White_FS { get { return new Color(Bin.FastSparkle, Bin.FastSparkle, Bin.FastSparkle); } }

            /// <summary>
            /// 亮红
            /// </summary>
            public static Color Red { get { return new Color(Bin.ON, Bin.OFF, Bin.OFF); } }
            /// <summary>
            /// 闪红
            /// </summary>
            public static Color Red_S { get { return new Color(Bin.Sparkle, Bin.OFF, Bin.OFF); } }
            /// <summary>
            /// 快闪红
            /// </summary>
            public static Color Red_FS { get { return new Color(Bin.FastSparkle, Bin.OFF, Bin.OFF); } }

            /// <summary>
            /// 亮绿
            /// </summary>
            public static Color Green { get { return new Color(Bin.OFF, Bin.ON, Bin.OFF); } }
            /// <summary>
            /// 闪绿
            /// </summary>
            public static Color Green_S { get { return new Color(Bin.OFF, Bin.Sparkle, Bin.OFF); } }
            /// <summary>
            /// 快闪绿
            /// </summary>
            public static Color Green_FS { get { return new Color(Bin.OFF, Bin.FastSparkle, Bin.OFF); } }

            /// <summary>
            /// 亮蓝
            /// </summary>
            public static Color Blue { get { return new Color(Bin.OFF, Bin.OFF, Bin.ON); } }
            /// <summary>
            /// 闪蓝
            /// </summary>
            public static Color Blue_S { get { return new Color(Bin.OFF, Bin.OFF, Bin.Sparkle); } }
            /// <summary>
            /// 快闪蓝
            /// </summary>
            public static Color Blue_FS { get { return new Color(Bin.OFF, Bin.OFF, Bin.FastSparkle); } }

            /// <summary>
            /// 亮橙
            /// </summary>
            public static Color Orange { get { return new Color(Bin.ON, Bin.ON, Bin.OFF); } }
            /// <summary>
            /// 闪橙
            /// </summary>
            public static Color Orange_S { get { return new Color(Bin.Sparkle, Bin.Sparkle, Bin.OFF); } }
            /// <summary>
            /// 快闪橙
            /// </summary>
            public static Color Orange_FS { get { return new Color(Bin.FastSparkle, Bin.FastSparkle, Bin.OFF); } }

            /// <summary>
            /// 亮紫
            /// </summary>
            public static Color Purple { get { return new Color(Bin.ON, Bin.OFF, Bin.ON); } }
            /// <summary>
            /// 闪紫
            /// </summary>
            public static Color Purple_S { get { return new Color(Bin.Sparkle, Bin.OFF, Bin.Sparkle); } }
            /// <summary>
            /// 快闪紫
            /// </summary>
            public static Color Purple_FS { get { return new Color(Bin.FastSparkle, Bin.OFF, Bin.FastSparkle); } }

            /// <summary>
            /// 亮天蓝
            /// </summary>
            public static Color Cyan { get { return new Color(Bin.OFF, Bin.ON, Bin.ON); } }
            /// <summary>
            /// 闪天蓝
            /// </summary>
            public static Color Cyan_S { get { return new Color(Bin.OFF, Bin.Sparkle, Bin.Sparkle); } }
            /// <summary>
            /// 快闪天蓝
            /// </summary>
            public static Color Cyan_FS { get { return new Color(Bin.OFF, Bin.FastSparkle, Bin.FastSparkle); } }
        }

        #endregion 亮灯颜色

        #region 功能
        public class Func
        {
            private Func() { }
            private string bin;
            /// <summary>
            /// 值转换--内部用
            /// </summary>
            internal string BinValue { get { return bin; } }
            /// <summary>
            /// 使用
            /// </summary>
            public static Func USED { get { return new Func { bin = "00" }; } }
            /// <summary>
            /// 不使用
            /// </summary>
            public static Func NOT_USED { get { return new Func { bin = "01" }; } }
            /// <summary>
            /// 不变
            /// </summary>
            public static Func NOT_CHANGE { get { return new Func { bin = "11" }; } }

        }
        #endregion

        #region MWU2060标签的m8模式新添加 是否启用

        /// <summary>
        /// 是否启用
        /// </summary>
        public class Enabled
        {
            private Enabled() { }

            private string bin;
            /// <summary>
            /// 值转换--内部用
            /// </summary>
            internal string BinValue { get { return bin; } }
            /// <summary>
            /// 使用
            /// </summary>
            public static Enabled USED { get { return new Enabled { bin = "1" }; } }
            /// <summary>
            /// 不使用
            /// </summary>
            public static Enabled NOT_USED { get { return new Enabled { bin = "0" }; } }
        }

        #endregion MWU2060标签的m8模式新添加 是否启用

        #region 表示条件
        /// <summary>
        /// MWU2414专用参数【滚动模式】，其他不要改动
        /// </summary>
        public Scroll FactorScroll { get; set; } = Scroll.OFF;
        /// <summary>
        /// 灯色
        /// </summary>
        public Color FactorColor { get; set; } = Color.White;
        /// <summary>
        /// 显示
        /// </summary>
        public Bin FactorSeq { get; set; } = Bin.ON;
        /// <summary>
        /// 蜂鸣器，MWU2414没有蜂鸣器，代表滚动速度
        /// </summary>
        public Bin FactorBuzzers { get; set; } = Bin.OFF;
        #endregion

        #region CONFIRM 按下后表示条件
        /// <summary>
        /// MWU2414专用参数【滚动模式】，其他不要改动
        /// </summary>
        public Scroll ConfirmScroll { get; set; } = Scroll.OFF;
        /// <summary>
        /// 灯色
        /// </summary>
        public Color ConfirmColor { get; set; } = Color.OFF;
        /// <summary>
        /// 显示
        /// </summary>
        public Bin ConfirmSeq { get; set; } = Bin.OFF;
        /// <summary>
        /// 蜂鸣器，MWU2414没有蜂鸣器，代表滚动速度
        /// </summary>
        public Bin ConfirmBuzzers { get; set; } = Bin.OFF;
        #endregion

        #region Fn 键按下后表示条件
        /// <summary>
        /// MWU2414专用参数【滚动模式】，其他不要改动
        /// </summary>
        public Scroll FnScroll { get; set; } = Scroll.No_Change;
        /// <summary>
        /// 灯色
        /// </summary>
        public Color FnColor { get; set; } = Color.White_S;
        /// <summary>
        /// 显示
        /// </summary>
        public Bin FnSeq { get; set; } = Bin.ON;
        /// <summary>
        /// 蜂鸣器，MWU2414没有蜂鸣器，代表滚动速度
        /// </summary>
        public Bin FnBuzzers { get; set; } = Bin.Sparkle;
        #endregion

        #region m4功能键
        /*CONFIRM，Fn 键
         * 00：不 使 用
         *01：使 用
         *11：不变化
         * Fn 键递减模式 不使用
            [b]Fn 键 使用
            [c]CONFIRM 不使用
        */
        /// <summary>
        /// 键递减模式
        /// </summary>
        public Func FnDecrease { get; set; } = Func.NOT_USED;
        /// <summary>
        /// Fn 键
        /// </summary>
        public Func FnKey { get; set; } = Func.NOT_USED;
        /// <summary>
        /// CONFIRM
        /// </summary>
        public Func ConfirmKey { get; set; } = Func.USED;
        #endregion

        #region MWU2060新加 m8功能键

        /// <summary>
        /// MWU2060专用 m8功能键 是否使用双层确认(即手环感应后,再拍确定按钮)
        /// </summary>
        public Enabled EpcDoubleConfirm { get; set; } = Enabled.NOT_USED;
        /// <summary>
        /// MWU2060专用 m8功能键 防错动作模式(SC001命令专用,如果非指定手环ID会闪白灯并打开蜂鸣器)
        /// </summary>
        public Enabled ErrorProofAction { get; set; } = Enabled.NOT_USED;

        #endregion MWU2060新加 m8功能键

        /// <summary>
        /// 获取亮灯颜色
        /// </summary>
        /// <param name="iMode"></param>
        protected Color GetLightColor(CommCmdLightModeEnum iMode)
        {
            switch (iMode)
            {// 亮灯模式
                case CommCmdLightModeEnum.BLUE:// 蓝
                    return Color.Blue;
                case CommCmdLightModeEnum.SPARKLE_BLUE:// 闪蓝
                    return Color.Blue_S;
                case CommCmdLightModeEnum.GREEN:// 绿
                    return Color.Green;
                case CommCmdLightModeEnum.SPARKLE_GREEN:// 闪绿
                    return Color.Green_S;
                case CommCmdLightModeEnum.LIGHT_BLUE:// 浅蓝
                    return Color.Cyan;
                case CommCmdLightModeEnum.SPARKLE_LIGHT_BLUE:// 闪浅蓝
                    return Color.Cyan_S;
                case CommCmdLightModeEnum.ORANGE:// 橙
                    return Color.Orange;
                case CommCmdLightModeEnum.SPARKLE_ORANGE:// 闪橙
                    return Color.Orange_S;
                case CommCmdLightModeEnum.PURPLE:// 紫
                    return Color.Purple;
                case CommCmdLightModeEnum.SPARKLE_PURPLE:// 闪紫
                    return Color.Purple_S;
                case CommCmdLightModeEnum.RED:// 红
                    return Color.Red;
                case CommCmdLightModeEnum.SPARKLE_RED:// 闪红
                    return Color.Red_S;
                case CommCmdLightModeEnum.WHITE:// 白
                    return Color.White;
                case CommCmdLightModeEnum.SPARKLE_WHITE:// 闪白
                    return Color.White_S;
                case CommCmdLightModeEnum.OFF:
                    return Color.OFF;
            }
            return Color.NoChange;
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="iState"></param>
        /// <returns></returns>
        protected Bin GetDeviceBuzzer(DeviceBuzzerStatuEnum iState)
        {
            switch (iState)
            {
                case DeviceBuzzerStatuEnum.OFF:
                    return Bin.OFF;
                case DeviceBuzzerStatuEnum.ON:
                    return Bin.ON;
                case DeviceBuzzerStatuEnum.SPARKLE:
                    return Bin.Sparkle;
                case DeviceBuzzerStatuEnum.FAST_SPARKLE:
                    return Bin.FastSparkle;
            }
            return Bin.NoChange;
        }
    }
}
